package com.ruoyi.web.controller.bank;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bank.domain.BankGreyRegister;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bank.domain.BankVillagers;
import com.ruoyi.bank.service.IBankVillagersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 村民信息管理Controller
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/bank/villagers")
public class BankVillagersController extends BaseController
{
    @Autowired
    private IBankVillagersService bankVillagersService;

    /**
     * 查询村民信息管理列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BankVillagers bankVillagers)
    {
        startPage();
        List<BankVillagers> list = bankVillagersService.selectBankVillagersList(bankVillagers);
        return getDataTable(list);
    }

    /**
     * 导出村民信息管理列表
     */

    @Log(title = "村民信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BankVillagers bankVillagers)
    {
        List<BankVillagers> list = bankVillagersService.selectBankVillagersList(bankVillagers);
        ExcelUtil<BankVillagers> util = new ExcelUtil<BankVillagers>(BankVillagers.class);
        util.exportExcel(response, list, "村民信息管理数据");
    }

    @Log(title = "村民信息管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BankVillagers> util = new ExcelUtil<BankVillagers>(BankVillagers.class);
        List<BankVillagers> villagersList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = bankVillagersService.importvillagers(villagersList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<BankVillagers> util = new ExcelUtil<BankVillagers>(BankVillagers.class);
        util.importTemplateExcel(response, "花名册数据");
    }
    /**
     * 获取村民信息管理详细信息
     */

    @GetMapping(value = "/id/{villagerId}")
    public AjaxResult getInfo(@PathVariable("villagerId") Long villagerId)
    {
        return success(bankVillagersService.selectBankVillagersByVillagerId(villagerId));
    }
    /**
     * 获取村民信息管理详细信息
     */
    @GetMapping(value = "/number/{villagerNumber}")
    public AjaxResult getNumber(@PathVariable("villagerNumber") String villagerNumber)
    {
        return success(bankVillagersService.selectBankVillagersByVillagerNumber(villagerNumber));
    }

    /**
     * 新增村民信息管理
     */

    @Log(title = "村民信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BankVillagers bankVillagers)
    {
        return toAjax(bankVillagersService.insertBankVillagers(bankVillagers));
    }

    /**
     * 修改村民信息管理
     */

    @Log(title = "村民信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BankVillagers bankVillagers)
    {
        return toAjax(bankVillagersService.updateBankVillagers(bankVillagers));
    }

    /**
     * 删除村民信息管理
     */

    @Log(title = "村民信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{villagerIds}")
    public AjaxResult remove(@PathVariable Long[] villagerIds)
    {
        return toAjax(bankVillagersService.deleteBankVillagersByVillagerIds(villagerIds));
    }
}
